package com.softstao.guoyu.ui.activity.agent;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseActivity;
import com.softstao.guoyu.global.SharePreferenceManager;
import com.softstao.guoyu.global.UserManager;
import com.softstao.guoyu.model.agent.ParentInfo;
import com.softstao.guoyu.model.agent.ParentInfoIndex;
import com.softstao.guoyu.mvp.interactor.agent.AgentInteractor;
import com.softstao.guoyu.mvp.presenter.agent.AgentPresenter;
import com.softstao.guoyu.mvp.viewer.agent.ParentInfoViewer;
import com.softstao.softstaolibrary.library.widget.CircleImageView;
import com.softstao.softstaolibrary.library.widget.CustomScrollerView;
import com.wangjie.androidinject.annotation.annotations.mvp.AIPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by vaikus on 2017/6/26.
 */

public class MyParentAgentActivity extends BaseActivity implements ParentInfoViewer{

    @AIPresenter(presenter = AgentPresenter.class, interactor = AgentInteractor.class)
    AgentPresenter presenter;

    @BindView(R.id.avatar)
    CircleImageView avatar;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.user_id)
    TextView userId;
    @BindView(R.id.mobile)
    TextView mobile;
    @BindView(R.id.wechat)
    TextView wechat;
    @BindView(R.id.qq)
    TextView qq;
    @BindView(R.id.payee_name)
    TextView payeeName;
    @BindView(R.id.accountPayee)
    TextView accountPayee;
    @BindView(R.id.openingBank)
    TextView openingBank;
    @BindView(R.id.scroll_view)
    CustomScrollerView scrollView;
    private ParentInfo parentInfo;

    @Override
    public int _ContentView() {
        return R.layout.activity_my_parent_agent;
    }

    @Override
    public void initView() {
        initTitle("我的上级");
    }

    private void initData() {
        if (!TextUtils.isEmpty(parentInfo.getAvatar())){
            Glide.with(context).load(parentInfo.getAvatar()).into(avatar);
        }else {
            avatar.setImageResource(R.mipmap.default_avatar);
        }
        if (!TextUtils.isEmpty(parentInfo.getName())){
            name.setText(parentInfo.getName());
        }
        userId.setText("用户ID："+String.valueOf(UserManager.getInstance().getUser().getParentId()));
        mobile.setText(parentInfo.getMobile());
        wechat.setText(parentInfo.getWechat());
        qq.setText(parentInfo.getQq());
        payeeName.setText(parentInfo.getPayee());
        accountPayee.setText(parentInfo.getAccountPayee());
        openingBank.setText(parentInfo.getOpeningBank());
    }

    @OnClick(R.id.contact)
    public void onViewClicked() {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + parentInfo.getMobile());
        intent.setData(data);
        startActivity(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        findParentInfo();
    }

    @Override
    public void findParentInfo() {
        presenter.getParentInfo(SharePreferenceManager.getInstance().getAgentId(), UserManager.getInstance().getUser().getParentId());
    }

    @Override
    public void getParentInfo(ParentInfoIndex parentInfoIndex) {
        if (parentInfoIndex!=null){
            if (parentInfoIndex.getParentInfo()!=null){
                this.parentInfo = parentInfoIndex.getParentInfo();
                initData();
            }
        }
    }
}
